package com.ruoyi.consumer.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.consumer.domain.CompanyBind;
import com.ruoyi.consumer.service.ICompanyBindService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 绑定员工Controller
 * 
 * @author ruoyi
 * @date 2023-10-13
 */
@RestController
@RequestMapping("/consumer/bind")
public class CompanyBindController extends BaseController
{
    @Autowired
    private ICompanyBindService companyBindService;

    /**
     * 查询绑定员工列表
     */
    @PreAuthorize("@ss.hasPermi('consumer:bind:list')")
    @GetMapping("/list")
    public TableDataInfo list(CompanyBind companyBind)
    {
        startPage();
        List<CompanyBind> list = companyBindService.selectCompanyBindList(companyBind);
        return getDataTable(list);
    }

    /**
     * 导出绑定员工列表
     */
    @PreAuthorize("@ss.hasPermi('consumer:bind:export')")
    @Log(title = "绑定员工", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CompanyBind companyBind)
    {
        List<CompanyBind> list = companyBindService.selectCompanyBindList(companyBind);
        ExcelUtil<CompanyBind> util = new ExcelUtil<CompanyBind>(CompanyBind.class);
        util.exportExcel(response, list, "绑定员工数据");
    }

    /**
     * 获取绑定员工详细信息
     */
    @PreAuthorize("@ss.hasPermi('consumer:bind:query')")
    @GetMapping(value = "/{bindId}")
    public AjaxResult getInfo(@PathVariable("bindId") Integer bindId)
    {
        return success(companyBindService.selectCompanyBindByBindId(bindId));
    }

    /**
     * 新增绑定员工
     */
    @PreAuthorize("@ss.hasPermi('consumer:bind:add')")
    @Log(title = "绑定员工", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CompanyBind companyBind)
    {
        return toAjax(companyBindService.insertCompanyBind(companyBind));
    }

    /**
     * 修改绑定员工
     */
    @PreAuthorize("@ss.hasPermi('consumer:bind:edit')")
    @Log(title = "绑定员工", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CompanyBind companyBind)
    {
        return toAjax(companyBindService.updateCompanyBind(companyBind));
    }

    /**
     * 删除绑定员工
     */
    @PreAuthorize("@ss.hasPermi('consumer:bind:remove')")
    @Log(title = "绑定员工", businessType = BusinessType.DELETE)
	@DeleteMapping("/{bindIds}")
    public AjaxResult remove(@PathVariable Integer[] bindIds)
    {
        return toAjax(companyBindService.deleteCompanyBindByBindIds(bindIds));
    }
}
